﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.Assert;
using CommunitySystem.Ctrls;
using CommunitySystem.PublicOfficialSelectionService;
using CommunitySystem.Views;
using EHR.Common;

namespace CommunitySystem
{
    public partial class ShenPiControl3 : AsyncCtrl, IReturnListenerc
    {
        #region IReturnListenerc 成员
        public void BeginReturn()
        {
            //Load();
        }
        #endregion
        public NavMoveSwitch Nav { get; set; }
        private PublicOfficialSelectionServiceClient Client = new PublicOfficialSelectionServiceClient();
        public ObservableCollection<RenQianGongShi> models = new ObservableCollection<RenQianGongShi>();
        public int OrgID = 0;
        private string OrgName = "";
        private ObservableCollection<RenQianTaoLun> _renqimodels = null;
        private bool _isls = false;
        public ShenPiControl3(int orgID, string orgName, ObservableCollection<RenQianTaoLun> models, bool isls)
        {
            InitializeComponent();
            _isls = isls;
            _renqimodels = models;
            OrgID = orgID;
            OrgName = orgName;
            if(Session.LoginUser.LoginName == "admin")
            {
                OKButton.Visibility = System.Windows.Visibility.Collapsed;
                //shenqing.Visibility = System.Windows.Visibility.Collapsed;
                //queren.Visibility = System.Windows.Visibility.Collapsed;
                scrol.IsEnabled = false;
            }
            else
            {
                OKButton.Visibility = System.Windows.Visibility.Visible;
                //shenqing.Visibility = System.Windows.Visibility.Visible;
                //shenqing.IsEnabled = false;
                //queren.Visibility = System.Windows.Visibility.Collapsed;
                btnnext.IsEnabled = false;
                scrol.IsEnabled = true;
            }
            Loaded();
        }

        public void Loaded()
        {
            Client.GetRenQianGongShiCompleted -= new EventHandler<GetRenQianGongShiCompletedEventArgs>(Client_GetRenQianGongShiCompleted);
            Client.GetRenQianGongShiCompleted += new EventHandler<GetRenQianGongShiCompletedEventArgs>(Client_GetRenQianGongShiCompleted);
            Client.GetRenQianGongShiAsync(OrgID);
        }

        void Client_GetRenQianGongShiCompleted(object sender, GetRenQianGongShiCompletedEventArgs e)
        {
            stackpanel.Children.Clear();
            if (e.Result != null && e.Result.Count > 0)
            {
                if (e.Result[0].ID != 0) btnnext.IsEnabled = true; //shenqing.IsEnabled = true;
                //if (e.Result[0].ID != 0 && Session.LoginUser.LoginName == "admin") queren.Visibility = System.Windows.Visibility.Visible;
                 OKButton.IsEnabled = true;
                models = e.Result;
                int count = ((ObservableCollection<RenQianGongShi>)e.Result).Count;
                for (int i = 0; i < count; i++)
                {
                    StackPanel s = new StackPanel();
                    s.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    s.Orientation = Orientation.Horizontal;

                    TextBlock tb1 = new TextBlock();
                    tb1.Text = "    经";
                    tb1.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tb1.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    s.Children.Add(tb1);

                    #region
                    //TextBox t = new TextBox();
                    //t.Tag = i;
                    //t.TextChanged += new TextChangedEventHandler(TextBox_TextChanged);
                    //if (!string.IsNullOrEmpty(e.Result[i].SNian)) t.Text = e.Result[i].SNian;
                    //t.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    //t.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    //t.Width = 60;
                    //t.Height = 25;
                    //Binding b1 = new Binding();
                    //b1.Source = e.Result[i];
                    //b1.Path = new PropertyPath("SNian");
                    //b1.Mode = BindingMode.TwoWay;
                    //BindingOperations.SetBinding(t, TextBox.TextProperty, b1);
                    //s.Children.Add(t);
                    
                    //TextBlock tb2 = new TextBlock();
                    //tb2.Text = "年";
                    //tb2.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    //tb2.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    //s.Children.Add(tb2);

                    //TextBox t1 = new TextBox();
                    //t1.Tag = i;
                    //t1.TextChanged += new TextChangedEventHandler(TextBox_TextChanged);
                    //if (!string.IsNullOrEmpty(e.Result[i].SYUe)) t1.Text = e.Result[i].SYUe;
                    //t1.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    //t1.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    //t1.Width = 60;
                    //t1.Height = 25;
                    //Binding b2 = new Binding();
                    //b2.Source = e.Result[i];
                    //b2.Path = new PropertyPath("SYUe");
                    //b2.Mode = BindingMode.TwoWay;
                    //BindingOperations.SetBinding(t1, TextBox.TextProperty, b2);
                    //s.Children.Add(t1);
                    
                    //TextBlock tb3 = new TextBlock();
                    //tb3.Text = "月";
                    //tb3.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    //tb3.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    //s.Children.Add(tb3);

                    //TextBox t2 = new TextBox();
                    //t2.Tag = i;
                    //t2.Name = "t2";
                    //t2.TextChanged += new TextChangedEventHandler(TextBox_TextChanged);
                    //if (!string.IsNullOrEmpty(e.Result[i].SRi)) t2.Text = e.Result[i].SRi;
                    //t2.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    //t2.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    //t2.Width = 60;
                    //t2.Height = 25;
                    //Binding b3 = new Binding();
                    //b3.Source = e.Result[i];
                    //b3.Path = new PropertyPath("SRi");
                    //b3.Mode = BindingMode.TwoWay;
                    //BindingOperations.SetBinding(t2, TextBox.TextProperty, b3);
                    //s.Children.Add(t2);

                    #endregion
                    DatePicker dp1 = new DatePicker();
                    if (!string.IsNullOrEmpty(e.Result[0].StartDate.ToString())) dp1.SelectedDate = e.Result[i].StartDate;
                    dp1.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    dp1.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    Binding b3 = new Binding();
                    b3.Source = e.Result[i];
                    b3.Path = new PropertyPath("StartDate");
                    b3.Mode = BindingMode.TwoWay;
                    BindingOperations.SetBinding(dp1, DatePicker.SelectedDateProperty, b3);
                    s.Children.Add(dp1);

                    TextBlock tb4 = new TextBlock();
                    tb4.Text = "至";
                    tb4.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tb4.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    s.Children.Add(tb4);

                    #region
                    //TextBox t3 = new TextBox();
                    //if (!string.IsNullOrEmpty(e.Result[i].ENian)) t3.Text = e.Result[i].ENian;
                    //t3.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    //t3.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    //t3.Width = 60;
                    //t3.Height = 25;
                    //Binding b4 = new Binding();
                    //b4.Source = e.Result[i];
                    //b4.Path = new PropertyPath("ENian");
                    //b4.Mode = BindingMode.TwoWay;
                    //BindingOperations.SetBinding(t3, TextBox.TextProperty, b4);
                    //s.Children.Add(t3);
                    
                    //TextBlock tb5 = new TextBlock();
                    //tb5.Text = "年";
                    //tb5.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    //tb5.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    //s.Children.Add(tb5);

                    //TextBox t4 = new TextBox();
                    //if (!string.IsNullOrEmpty(e.Result[i].EYue)) t4.Text = e.Result[i].EYue;
                    //t4.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    //t4.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    //t4.Width = 60;
                    //t4.Height = 25;
                    //Binding b5 = new Binding();
                    //b5.Source = e.Result[i];
                    //b5.Path = new PropertyPath("EYue");
                    //b5.Mode = BindingMode.TwoWay;
                    //BindingOperations.SetBinding(t4, TextBox.TextProperty, b5);
                    //s.Children.Add(t4);
                    
                    //TextBlock tb6 = new TextBlock();
                    //tb6.Text = "月";
                    //tb6.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    //tb6.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    //s.Children.Add(tb6);

                    //TextBox t5 = new TextBox();
                    //if (!string.IsNullOrEmpty(e.Result[i].ERi)) t5.Text = e.Result[i].ERi;
                    //t5.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    //t5.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    //t5.Width = 60;
                    //t5.Height = 25;
                    //Binding b6 = new Binding();
                    //b6.Source = e.Result[i];
                    //b6.Path = new PropertyPath("ERi");
                    //b6.Mode = BindingMode.TwoWay;
                    //BindingOperations.SetBinding(t5, TextBox.TextProperty, b6);
                    //s.Children.Add(t5);
                    #endregion

                    DatePicker dp2 = new DatePicker();
                    if (!string.IsNullOrEmpty(e.Result[0].EndDate.ToString())) dp2.SelectedDate = e.Result[i].EndDate;
                    dp2.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    dp2.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    Binding b31 = new Binding();
                    b31.Source = e.Result[i];
                    b31.Path = new PropertyPath("EndDate");
                    b31.Mode = BindingMode.TwoWay;
                    BindingOperations.SetBinding(dp2, DatePicker.SelectedDateProperty, b31);
                    s.Children.Add(dp2);


                    TextBlock tb7 = new TextBlock();
                    tb7.Text = "公示" + e.Result[i].EmpName + "同志转任" + e.Result[i].Department_Duty + " " + e.Result[i].Duty;
                    tb7.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tb7.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    s.Children.Add(tb7);

                    #region  反应情况
                    TextBlock tb81 = new TextBlock();
                    tb81.Margin = new Thickness(3, 3, 3, 3);
                    tb81.Text = "   反应情况：";
                    tb81.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tb81.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;

                    TextBox t81 = new TextBox();
                    t81.Width = 250;
                    t81.Height = 25;

                    if (!string.IsNullOrEmpty(e.Result[i].FYQk)) t81.Text = e.Result[i].FYQk;
                    t81.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    t81.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    Binding b91 = new Binding();
                    b91.Source = e.Result[i];
                    b91.Path = new PropertyPath("FYQk");
                    b91.Mode = BindingMode.TwoWay;
                    BindingOperations.SetBinding(t81, TextBox.TextProperty, b91);

                    #endregion

                    TextBlock tb8 = new TextBlock();
                    tb8.Margin = new Thickness(3, 3, 3, 3);
                    tb8.Text = "处理意见如下：";
                    tb8.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tb8.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;

                    TextBox t8 = new TextBox();
                    t8.Width = 250;
                    t8.Height = 25;
                    
                    if (!string.IsNullOrEmpty(e.Result[i].ChuLiQingKuang)) t8.Text = e.Result[i].ChuLiQingKuang;
                    t8.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    t8.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    Binding b9 = new Binding();
                    b9.Source = e.Result[i];
                    b9.Path = new PropertyPath("ChuLiQingKuang");
                    b9.Mode = BindingMode.TwoWay;
                    BindingOperations.SetBinding(t8, TextBox.TextProperty, b9);

                    #region   是否同意

                    TextBlock tb8s = new TextBlock();
                    tb8s.Margin = new Thickness(3, 3, 3, 3);
                    tb8s.Text = "是否同意转任：";
                    tb8s.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tb8s.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;


                    ComboBox cb1 = new ComboBox();
                    cb1.Tag = e.Result[i];
                    cb1.SelectionChanged += new SelectionChangedEventHandler(cb1_SelectionChanged);
                    cb1.Width = 90;
                    cb1.Height = 25;
                    ComboBoxItem ci11 = new ComboBoxItem();
                    ci11.Content = "同意";
                    ComboBoxItem ci111 = new ComboBoxItem();
                    ci111.Content = "不同意";
                    cb1.Items.Add(ci11);
                    cb1.Items.Add(ci111);

                    if (!string.IsNullOrEmpty(e.Result[i].ISTongyi))
                    {
                        if (e.Result[i].ISTongyi == "同意")
                        {
                            cb1.SelectedIndex = 0;
                        }
                        else
                        {
                            cb1.SelectedIndex = 1;
                        }
                    }
                    cb1.Margin = new Thickness(3, 3, 3, 3);     
                    //sp.Children.Add(cb1);
                    #endregion

                    StackPanel sp = new StackPanel();
                    sp.Orientation = Orientation.Horizontal;
                    sp.Visibility = System.Windows.Visibility.Collapsed;

                    sp.Children.Add(tb81);
                    sp.Children.Add(t81);
                    sp.Children.Add(tb8);
                    sp.Children.Add(t8);
                    sp.Children.Add(tb8s);
                    sp.Children.Add(cb1);


              

                    ComboBox cb = new ComboBox();
                    cb.Width = 150;
                    cb.Height = 25;
                    cb.Tag = e.Result[i];
                    cb.SelectionChanged += new SelectionChangedEventHandler(cb_SelectionChanged);
                    ComboBoxItem ci = new ComboBoxItem();
                    ci.Content = "未收到情况反映";
                    //ci.IsSelected = true;
                    ComboBoxItem ci1 = new ComboBoxItem();
                    ci1.Content = "有情况反映";
                    cb.Items.Add(ci);
                    cb.Items.Add(ci1);

                  
                    dic.Add(cb, sp);
                 

                    if (!string.IsNullOrEmpty(e.Result[i].IsFanYing))
                    {
                        if (e.Result[i].IsFanYing == "未收到情况反映")
                        {
                            cb.SelectedIndex = 0;
                        }
                        else
                        {
                            cb.SelectedIndex = 1;
                        }
                    }else
                        cb.SelectedIndex = 0;

                    cb.Margin = new Thickness(3, 3, 3, 3);
                    //Binding b = new Binding();
                    //b.Source = e.Result[i];
                    //b.Path = new PropertyPath("IsFanYing");
                    //b.Mode = BindingMode.TwoWay;
                    //BindingOperations.SetBinding(cb, ComboBox.SelectedItemProperty, b);
                    s.Children.Add(cb);

                    
                    

                    stackpanel.Children.Add(s);
                    stackpanel.Children.Add(sp);
                }
            }
            else OKButton.IsEnabled = false;
        }

        void cb1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
       
            ((RenQianGongShi) ((ComboBox) sender).Tag).ISTongyi = ((System.Windows.Controls.ContentControl)
                                                                  (((ComboBoxItem) ((ComboBox) sender).SelectedItem))).
                Content.
                ToString();
     
        }

        private string pattern = @"^[0-9]+([.]{1}[0-9]+){0,1}$";
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            Match m = Regex.Match(((TextBox)sender).Text, pattern);   // 匹配正则表达式
            if (!string.IsNullOrEmpty(((TextBox)sender).Text))
            {
                if (!m.Success)   // 输入的不是数字
                {
                    SilverlightMessageBoxLibrary.Message.ErrorMessage("只能输入数字！");
                    ((TextBox)sender).Text = "";
                    return;
                    //((TextBox)sender).Text = param1;   // textBox内容不变

                    // 将光标定位到文本框的最后
                    //((TextBox)sender).SelectionStart = ((TextBox)sender).Text.Length;
                }
                if(((TextBox)sender).Name == "t2")
                {
                    var ii = models[Convert.ToInt32(((TextBox) sender).Tag)];
                    try
                    {
                        if(!string.IsNullOrEmpty(ii.SNian) && !string.IsNullOrEmpty(ii.SYUe) && !string.IsNullOrEmpty(ii.SRi))
                        {
                            DateTime dt = Convert.ToDateTime(ii.SNian + "-" + ii.SYUe + "-" + ii.SRi);
                            ii.ENian = dt.AddDays(7).Year.ToString();
                            ii.EYue = dt.AddDays(7).Month.ToString();
                            ii.ERi = dt.AddDays(7).Day.ToString();
                        }
                    }
                    catch(Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
            

        }

        private Dictionary<ComboBox, StackPanel> dic = new Dictionary<ComboBox,StackPanel>();
        void cb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((RenQianGongShi)((ComboBox)sender).Tag).IsFanYing = ((System.Windows.Controls.ContentControl)
                                                                  (((ComboBoxItem)((ComboBox)sender).SelectedItem))).
                Content.
                ToString();
            if (dic.Keys.Contains(((ComboBox)sender)))
            if(((ComboBox)sender).SelectedIndex == 1)
            {
                dic[((ComboBox) sender)].Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                dic[((ComboBox)sender)].Visibility = System.Windows.Visibility.Collapsed;
            }

            #region

            #endregion
        }

        private int c = 0;
        private string error = "";
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            //foreach (RenQianGongShi i in models)
            //{
            //    if(string.IsNullOrEmpty(i.SNian) || string.IsNullOrEmpty(i.SYUe) || string.IsNullOrEmpty(i.SYUe)
            //        ||string.IsNullOrEmpty(i.ENian)||string.IsNullOrEmpty(i.EYue)||string.IsNullOrEmpty(i.ERi))
            //    {
            //        MessageBox.Show("请正确填写年月日信息！");
            //        return;
            //    }
            //}
            //foreach (RenQianGongShi i in models)
            //{
            //    if (Convert.ToDateTime(i.SNian + "-" + i.SYUe + "-" + i.SRi).AddDays(7) != Convert.ToDateTime(i.ENian + "-" + i.EYue + "-" + i.ERi))
            //    {
            //        error += "\r\n" + i.EmpName + "同志转任公示时间有误！";
            //    }
            //}
            if (Validate())
            {
                if (MessageBox.Show(error + "\r\n确定上报会议结果吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {

                    foreach (RenQianGongShi i in models)
                    {
                        if (i.IsFanYing == "未收到情况反映") { i.ChuLiQingKuang = ""; i.ISTongyi = "同意"; i.FYQk = ""; }

                        Client.InsertRenQianGongShiCompleted -= new EventHandler<InsertRenQianGongShiCompletedEventArgs>(Client_InsertRenQianGongShiCompleted);
                        Client.InsertRenQianGongShiCompleted += new EventHandler<InsertRenQianGongShiCompletedEventArgs>(Client_InsertRenQianGongShiCompleted);
                        Client.InsertRenQianGongShiAsync(i);
                        c += 1;
                    }
                }
            }
        }

        void Client_InsertRenQianGongShiCompleted(object sender, InsertRenQianGongShiCompletedEventArgs e)
        {
            if (c == models.Count)
            {
                c = c - 1;
                //SilverlightMessageBoxLibrary.Message.InfoMessage("上报成功！");
                //shenqing.IsEnabled = true;

                ShenPiControl4 view = new ShenPiControl4(Convert.ToInt32(OrgID), OrgName, models, _isls);
                view.Nav = Nav;
                Nav.ShowNextPage(OrgName + "-确认转任", view, this);
            }
        }
       private bool Validate()
        {
            if (models != null && models.Count > 0)
            {
                var d = models.Where(c => c.IsFanYing == "有情况反映").FirstOrDefault();
                if (d != null)
                {
                    if (string.IsNullOrEmpty(d.FYQk))
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage(d.EmpName + "反应情况不能为空!");
                        return false;
                    }

                    if (string.IsNullOrEmpty(d.ChuLiQingKuang))
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage(d.EmpName + "处理意见不能为空!");
                        return false;
                    }
                    if (string.IsNullOrEmpty(d.ISTongyi))
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择"+d.EmpName + "是否同意转任选项!");
                        return false;
                    }
                }
                foreach (var item in models)
                {
                    if (item.StartDate == null || item.EndDate == null)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage(item.EmpName + "公示时间不能为空!");
                        return false;
                    }
                    if (item.StartDate > item.EndDate)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage(item.EmpName + "结束时间不能早于开始时间!");
                        return false;
                    }
                    foreach (var item1 in _renqimodels.Where(p => p.EmpName == item.EmpName).ToList())
                    {
                        if (item1.TYDate > item.StartDate)
                        {
                            SilverlightMessageBoxLibrary.Message.ErrorMessage(item.EmpName + "公示的开始时间不能早于党（工）委（组）讨论时间!");
                            return false;
                        }
                    }
                }
            }
            else
            {
                return false;
            }
            return true;
        }
        private void shenqing_Click(object sender, RoutedEventArgs e)
        {
            //string ss = "";
            //if (MessageBox.Show("确定申请转任吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            //{
            //    //foreach (RenQianGongShi i in models)
            //    //{
            //    //    if (i.IsShenQingZhuanRen == false)
            //    //    {
            //    //        SilverlightMessageBoxLibrary.Message.ErrorMessage("还未提交转任申请，不可确认转任！");
            //    //        return;
            //    //    }
            //    //}
            //    foreach(RenQianGongShi i in models)
            //    {
            //        ss += i.PublicOfficialRecordID.ToString() + ",";
            //    }
            //    Client.QueRenShenQingZhuanRenCompleted -= new EventHandler<QueRenShenQingZhuanRenCompletedEventArgs>(Client_QueRenShenQingZhuanRenCompleted);
            //    Client.QueRenShenQingZhuanRenCompleted += new EventHandler<QueRenShenQingZhuanRenCompletedEventArgs>(Client_QueRenShenQingZhuanRenCompleted);
            //    Client.QueRenShenQingZhuanRenAsync(ss.Substring(0, ss.Length - 1));
            //}

            ShenPiControl4 view = new ShenPiControl4(Convert.ToInt32(OrgID), OrgName, models, _isls);
            view.Nav = Nav;
            Nav.ShowNextPage(OrgName + "-确认转任", view, this);
        }

        void Client_QueRenShenQingZhuanRenCompleted(object sender, QueRenShenQingZhuanRenCompletedEventArgs e)
        {
            if(e.Result == true)
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("申请成功！");
            }
            else
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("请完整填写任前管理信息！"); 
            }
        }

        private void queren_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("确定转任吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                foreach (RenQianGongShi i in models)
                {
                    if (i.IsZhuanRen == true)
                    {
                        SilverlightMessageBoxLibrary.Message.ErrorMessage("已转任，不可重复操作！");
                        return;
                    }
                }
                foreach (RenQianGongShi i in models)
                {
                    Client.QueRenZhuanRenCompleted -= new EventHandler<QueRenZhuanRenCompletedEventArgs>(Client_QueRenZhuanRenCompleted);
                    Client.QueRenZhuanRenCompleted += new EventHandler<QueRenZhuanRenCompletedEventArgs>(Client_QueRenZhuanRenCompleted);
                    Client.QueRenZhuanRenAsync(i.PublicOfficialRecordID);
                    cd += 1;
                }
            }

        
        }

        private int cd = 0;
        void Client_QueRenZhuanRenCompleted(object sender, QueRenZhuanRenCompletedEventArgs e)
        {
            if (cd == models.Count)
            {
                cd = cd - 1;
                SilverlightMessageBoxLibrary.Message.InfoMessage("确认转任成功！");
            }
        }

        private void btnnext_Click(object sender, RoutedEventArgs e)
        {
            ShenPiControl4 view = new ShenPiControl4(Convert.ToInt32(OrgID), OrgName, models, _isls);
            view.Nav = Nav;
            Nav.ShowNextPage(OrgName + "-确认转任", view, this);
        }
    }
}
